// src/main/java/com/qst/itoffer/mapper/UserMapper.java
package com.qst.itoffer.mapper;

import com.qst.itoffer.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM tb_users WHERE USER_LOGNAME = #{username}")
    User findByUsername(String username);

    @Insert("INSERT INTO tb_users (user_logname, user_pwd, user_realname, user_email, user_role, user_state) " +
            "VALUES (#{userLogname}, #{userPwd}, #{userRealname}, #{userEmail}, #{userRole}, #{userState})")
    void insertUser(User user);


    @Update("UPDATE tb_user SET user_status = #{status} WHERE user_id = #{userId}")
    void updateUserStatus(Long userId, Integer status);
    //分页查询
    @Select("SELECT * FROM tb_users LIMIT #{start}, #{pageSize}")
    List<User> selectPage(@Param("start") int start, @Param("pageSize") int pageSize);
    //查询总记录数
    @Select("SELECT COUNT(*) FROM tb_users")
    int selectCount();
    //根据id查询
    @Select("SELECT * FROM tb_users WHERE user_id = #{userId}")
    User selectById(Integer userId);
    //修改数据private String userLogname;
    //    private String userPwd;
    //    private String userRealname;
    //    private String userEmail;
    //    private Integer userRole;
    //    private Integer userState;
    @Update("UPDATE tb_users SET user_logname= #{userLogname}, user_pwd= #{userPwd}, " +
            " user_realname=#{userRealname}, user_email=#{userEmail}, " +
            "user_role=#{userRole}, user_state=#{userState} WHERE user_id=#{userId}")

    void update(User user);

    //查询所有用户
    @Select("SELECT * FROM tb_users")
    List<User> selectAll();

    @Delete("DELETE FROM tb_users WHERE user_id = #{userId}")
    void deleteUser(Integer userId);
}